<template>
    <f7-page>
       <qm-currentcy-navbar title="我的签名">
      <template #nav-right>
        <f7-icon f7="ellipsis"></f7-icon>
      </template>
    </qm-currentcy-navbar>
        <f7-block class="text-align-center"
                  style="padding: 10px;background-color:#fff;">
            <img v-if="signImg"
                 :src="signImg"
                 style="
          width: 100%;
          border: 1px solid rgb(197 195 195);
          border-radius: 10px;
        " />
            <span v-else>尚未签名</span>
        </f7-block>
        <f7-list>
            <li>
                <a class="item-link"
                   @click="openSignPopup()">
                    <div class="item-content">
                        <div class="item-inner"
                             style="padding-right: 35px">
                            <div class="item-title">
                                {{ signImg ? "重新签名" : "签名认证" }}
                            </div>
                        </div>
                    </div>
                </a>
            </li>
        </f7-list>
        <qm-sign ref="signSheet"
                 :saveSignCallback="saveSignCallback" />
    </f7-page>
</template>
<script>
import controller from "@/libs/framework/controller";

export default class List extends controller {
    onBeforeInit () {
        this.urls = {
            model: "/api/signature/signature/getSignature",
        };
    }
    mixin () {
        return {
            data () {
                return {
                    signImg: undefined,
                };
            },
            methods: {
                /**
                 * 保存签名
                 * @param {Boolean} isNext 是否保存并继续
                 */
                saveSignCallback (signImgData) {
                    var self = this;
                    if (!signImgData) {
                        return;
                    }

                    self.$refs.signSheet.doSaveSign(signImgData, null, () => {
                        self.signImg = signImgData;
                    });
                },
                /**  打开签名画板 */
                openSignPopup () {
                    var self = this;
                    self.$refs.signSheet.openAction();
                },
            },
            mounted () {
                var sign = this.$refs.signSheet;
                sign.showResignBtn = false;
                sign.showNextBtn = false;
            },
        };
    }

    async onInit () {
        let user = this.$f7.data.currentUser;
        if (!user) {
            await this.$framework.account.getUser();
        }
        console.log(this.context.signImg, "onInit")
        this.context.signImg = null;
        this.context.userId = user.userId;
    }

    onBeforeQuery (type, conditions, parems) {
        conditions.userId = this.context.userId || this.$f7.data.currentUser.userId;
    }
    onAfterQuery (type, isSuccess, result) {
        if (isSuccess && result?.success) {
            this.context.signImg = result.parameters.sign.signImg;
        }
        return super.onAfterQuery(type, isSuccess, result);
    }

    disableCache () {
        return true;
    }

}
</script>
